# 1. 导入需要的包
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# 2. 创建浏览器对象,并打开指定网址
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("http://www.baidu.com")

# 3. 元素定位+元素操作
locator = (By.ID, "kw")
search = EC.presence_of_element_located(locator)(driver)
search.send_keys("EC模块")

# 3.1 显示等待+EC模块
# 判断元素是否存在
# search_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located(locator))

# 判断元素是否可见
search_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located(locator))
search_box.send_keys("显示等待+EC模块")

# 定位百度首页的input标签
# input_loc = (By.TAG_NAME, "input")
# input_tag = WebDriverWait(driver, 10).until(EC.presence_of_element_located(input_loc))
# print(input_tag)

# 4. 关闭浏览器
sleep(3)
driver.quit()
